<template>
  <Layout>
    <van-nav-bar
      title="vite-webapp-template"
      left-text="返回"
      left-arrow
      @click-left="toHome"
    />
    <van-form style="margin-top: 50px">
      <div style="margin: 15px 0">
        <van-button block type="primary" @click="get"> 发送get请求 </van-button>
        <van-button style="margin-top: 20px" block type="success" @click="post">
          发送post请求
        </van-button>
      </div>
    </van-form>
  </Layout>
</template>

<script setup lang="ts">
import { getMockApiData, postData } from "@/api/mock";
import { useRouter } from "vue-router";
import { showToast } from "vant";
const router = useRouter();
const get = () => {
  getMockApiData({}).then((res) => {
    const { code, data } = res;
    if (code === 0 && data) {
      showToast(`get请求成功, 共${data.rows.length}条数据。`);
    }
  });
};
const post = () => {
  postData({ name: "张三" }).then(() => {
    showToast("post请求成功!");
  });
};
const toHome = () => {
  router.push("/home");
};
</script>

<style scoped lang="scss"></style>
